Perps V3
Perps V3 is live on Base
Perps V3.1 features and updates
Cross margin: account margin can be used across multiple positions on markets
Only async (delayed offchain) orders: atomic orders can be gamed very easily by front runners; async orders seems to be the way forward in general.
No order cancellation: you couldn't cancel within settlement window anyway so it was pointless to add cancel after the order has expired. Removed one extra action for keepers to perform and LPs to pay for.
Accounts with Role Based Access Control for modifying collateral, opening/closing positions - enabling full extensibility and composability.
Improved liquidations and no more endorsed liquidators
Utilization interest rate
Constraints to note
Single position per market
Single pending order
Expected features for v3.2
Multi collateral: accepts any synths configured in the system as margin for an account
SDK
To better understand how to trade perps, see
Workflow
Factory Owner
This is permissioned
Each proxy is considered to be one “supermarket”, and is initialized with the factory owner as the owner of this supermarket. The supermarket consists of a set of markets that it controls for which cross margin is applied. Each account that’s created is scoped to the supermarket and cannot be used on other supermarkets.
Supermarkets can only be initialized once which registers them with the Core system using the following call (returns the registered market id with core system):
Owner can set other global parameters that apply to all markets:
synthetix-v3/GlobalPerpsMarketConfiguration.sol at main · Synthetixio/synthetix-v3
Create perps market:
Two markets have been created on OP Goerli so far:
100
: ETH market200
: BTC market
Set configuration parameters
If you need the configuration of any of the above created markets, here are the functions you can call:
synthetix-v3/PerpsMarketConfiguration.sol at main · Synthetixio/synthetix-v3
Add settlement strategy for async orders:
A strategy has been added on OP goerli. You can always query
getSettlementStrategy
to get the details.
Trader
This is how integrators or front ends
Create account:
function createAccount(uint128 requestedAccountId) external;
Re-using the
AccountModule
from v3 core system which comes packaged with RBAC.The account owner can delegate
PERPS_MODIFY_COLLATERAL
role to another address using:
Modify collateral:
Use
0
assynthMarketId
for snxUSD.Use any other synth that has a
maxCollateralAmount
set by owner of factory to add to account’s margin.By providing a negative
amountDelta
, you are able to withdraw collateral of your choosing.Note: there are checks in place to ensure you cannot remove more than the required maintenance margin.
Commit Order:
sizeDelta
is the change in size of the position. Can determine long/short based on this value.A settlement strategy is required in order to commit orders. Here’s an example of one that uses a pyth offchain settlement strategy:
Liquidation Keepers
Call either:
function liquidate(uint128 accountId) external
If the account is already flagged for liquidation, the call will proceed with liquidating as much of the account’s position as possible.
If the account is not, it will check if the account is eligible and proceed to liquidate.
Otherwise, the call reverts.
function liquidateFlagged() external
Iterates through all accounts flagged for liquidation and attempts to liquidate.
Gas could be high but so are the rewards 💰
Settlement Keepers
function settle(uint128 marketId, uint128 accountId) external
if the order is valid and within settlement window, this function will settle the order and update its accounting of the new position.
Other Notes:
Liquidation Margins
An account is subject to margin requirements as determined by the following values configurable for each market:
When opening a position on a given market, the initial margin requirement is a fraction of the notional value. The fraction is determined by calculating the size’s impact on the skew (position size / skewScale), multiplied by the initialMarginFraction
plus the minimumInitialMarginScalar
.
Once a positive is live, the liquidation threshold is determined by the maintenceMargin
which is the initialMargin requirement multiplied by the configured maintenceMarginScalar
.
To determine if an account is liquidatable, the account’s availableMargin
must be greater than all calculated maintenance margins combined for each market the account has a position open. The maintenance margin also includes the liquidation settlement reward configured per market as a % of the notional size being liquidated.
availableMargin
is determined by subtracting any unrealized pnl to the available collateral margin.
Available functions that will come in handy:
Estimate Order Validity
There are some functions you can call initially to determine if an order will go through:
Max Liquidatable Amount
Each market has parameters that dictate how much can be liquidated at any given point.
The equation for max liquidation per second is as follows:
Note: the multiplier is an additional way to limit max liquidation amount per market.
Based on the configured window, maxSecondsInLiquidationWindow
, and maxLiquidationAmountPerSecond
, the max liquidatable amount in any given window is:
maxSecondsInLiquidationWindow * maxLiquidationAmountPerSecond
Example:
In this scenario, a max of 500 ETH
can be liquidated in a 5 second window.
Last updated